﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace WindowsFormsApplication1
{
    public partial class newb : UserControl
    {

        public newb()
        {
            InitializeComponent();
        }


        private void add_product_Click(object sender, EventArgs e)
        {
            string connection = "Data Source=|DataDirectory|\\Model\\Database1.sdf";
            string[] x1 = new string[5] { "@apID", "@userID", "@Name", "@Product", "@Price" };
            string[] values1 = new string[5] {""+Globals.dept,""+Globals.userID,Globals.userName,txt_product.Text,txt_price.Text};
            string q1 = "INSERT INTO shopping (apaID,userID,Name,Product,Price) VALUES(@apID, @userID, @Name, @Product, @Price)";

            if (Controller.Control.Insert_Update(q1, connection, x1, values1) == 1)
                MessageBox.Show("new buyment was added!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);

            string q2 = "UPDATE balance SET bala = bala+@Price WHERE userID = @userID ";
            string[] x2 = new string[2] { "@userID", "@Price" };
            string[] values2 = new string[2] { "" + Globals.userID, txt_price.Text };

            if (Controller.Control.Insert_Update(q2, connection, x2, values2) == 1)
                MessageBox.Show("balance was updated!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
